package com.bestow.basic.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bestow.common.annotation.Log;
import com.bestow.common.core.controller.BaseController;
import com.bestow.common.core.domain.AjaxResult;
import com.bestow.common.enums.BusinessType;
import com.bestow.basic.domain.FndProvince;
import com.bestow.basic.service.IFndProvinceService;
import com.bestow.common.utils.poi.ExcelUtil;
import com.bestow.common.core.page.TableDataInfo;

/**
 * 行政区域定义Controller
 * 
 * @author liliu
 * @date 2022-09-06
 */
@RestController
@RequestMapping("/basic/fndProvince")
public class FndProvinceController extends BaseController
{
    @Autowired
    private IFndProvinceService fndProvinceService;

    /**
     * 查询行政区域定义列表
     */
    @PreAuthorize("@ss.hasPermi('basic:fndProvince:list')")
    @GetMapping("/list")
    public TableDataInfo list(FndProvince fndProvince)
    {
        startPage();
        List<FndProvince> list = fndProvinceService.selectFndProvinceList(fndProvince);
        return getDataTable(list);
    }

    /**
     * 导出行政区域定义列表
     */
    @PreAuthorize("@ss.hasPermi('basic:fndProvince:export')")
    @Log(title = "行政区域定义", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FndProvince fndProvince)
    {
        List<FndProvince> list = fndProvinceService.selectFndProvinceList(fndProvince);
        ExcelUtil<FndProvince> util = new ExcelUtil<FndProvince>(FndProvince.class);
        util.exportExcel(response, list, "行政区域定义数据");
    }

    /**
     * 获取行政区域定义详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:fndProvince:query')")
    @GetMapping(value = "/{province}")
    public AjaxResult getInfo(@PathVariable("province") String province)
    {
        return AjaxResult.success(fndProvinceService.selectFndProvinceByProvince(province));
    }

    /**
     * 新增行政区域定义
     */
    @PreAuthorize("@ss.hasPermi('basic:fndProvince:add')")
    @Log(title = "行政区域定义", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FndProvince fndProvince)
    {
        return toAjax(fndProvinceService.insertFndProvince(fndProvince));
    }

    /**
     * 修改行政区域定义
     */
    @PreAuthorize("@ss.hasPermi('basic:fndProvince:edit')")
    @Log(title = "行政区域定义", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FndProvince fndProvince)
    {
        return toAjax(fndProvinceService.updateFndProvince(fndProvince));
    }

    /**
     * 删除行政区域定义
     */
    @PreAuthorize("@ss.hasPermi('basic:fndProvince:remove')")
    @Log(title = "行政区域定义", businessType = BusinessType.DELETE)
	@DeleteMapping("/{provinces}")
    public AjaxResult remove(@PathVariable String[] provinces)
    {
        return toAjax(fndProvinceService.deleteFndProvinceByProvinces(provinces));
    }
}
